#!/bin/bash

#go build gows
#nohup ./gows > /dev/null 2>&1 &

bin="./gows"
pidFile="nohup.pid"
outFile="/dev/null"

function stop () {
    if [ -f $pidFile ]; then
        pid=$(cat $pidFile)
        kill $pid
        rm -f $pidFile
    fi    
}


function start () {
    stop
    nohup $bin > $outFile 2>&1 &
    echo $! > $pidFile
}

function restart () {
    start
}

case $# in
0)
    start
    ;;
1)
    if [ $1 = "start" -o $1 = "restart" ]; then
	start
	echo "ok! started"
    elif [ $1 = "stop" ]; then
	stop
	echo "ok! stoped"
    else
	echo "useg: start start/stop/restart"
    fi 
    ;;
esac
